package twelvethDay;

import java.util.Stack;

public class EvalRPN {
    public static void main(String[] args) {
        String[] s = {"10","6","9","3","+","-11","*","/","*","17","+","5","+"};
        System.out.println(evalRPN(s));
    }
    public static int evalRPN(String[] tokens) {
        Stack<Integer> ans = new Stack<>();
        for (String token : tokens) {
            if (token.equals("+")){
                Integer popa = ans.pop();
                Integer popb = ans.pop();
                ans.push(popa + popb);
            } else if (token.equals("-")) {
                Integer popa = ans.pop();
                Integer popb = ans.pop();
                ans.push(popb - popa);
            } else if (token.equals("*")) {
                Integer popa = ans.pop();
                Integer popb = ans.pop();
                ans.push(popa * popb);
            } else if (token.equals("/")) {
                Integer popa = ans.pop();
                Integer popb = ans.pop();
                ans.push(popb / popa);
            } else {
                ans.push(Integer.parseInt(token));
            }
        }

        return ans.pop();
    }
}
